package org.example.trackpackage.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.model.common.Result;
import org.example.model.common.ResultCodeEnum;
import org.example.model.domain.TrackPackage;
import org.example.trackpackage.service.TrackPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/trackpackage")
@Slf4j
public class TrackPackageController {

    @Autowired
    TrackPackageService trackPackageService;

    @GetMapping("/list/{baoguoid}")
    public Result<TrackPackage> list(@PathVariable("baoguoid") Integer baoguoid){
        System.out.println(baoguoid);
        List<TrackPackage> trackPackage = trackPackageService.findTrackPackage(baoguoid);
        return Result.build(trackPackage, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/update")
    public Result<TrackPackage> update(@RequestBody TrackPackage trackPackage){
        log.info("取件码和包裹id:{}", trackPackage);
        int updatecode = trackPackageService.updatecode(trackPackage);
        return Result.build(updatecode, ResultCodeEnum.SUCCESS);
    }
}
